package org.seckill.controller;

import org.seckill.entity.Demo;
import org.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2017-8-15.
 */
@Controller
@RequestMapping("demo")
public class demoCotroller {

    @Autowired
    private SeckillService seckillService;

    @RequestMapping()
    public String demoPage(HttpServletRequest request,Model model) {

        return "demo";
    }

    @RequestMapping("/list")
    @ResponseBody
    public List<Demo> research(@RequestParam("searchText")String text, HttpServletRequest request) {

        System.out.println(text);
        String searchText = request.getParameter("searchText");
        if (searchText != null) {
            List<Demo> demos = seckillService.searchList(searchText);
            if (demos != null) return demos;
            //model.addAttribute("demos", demos);
        }
        return null;
    }

}
